import { createBrowserRouter, redirect } from "react-router-dom";
import Login from "../pages/Login";
import Register from "../pages/register";
import Home from "../pages/home";
import TabLayout from "../pages/tabLayout";
import Property from "../pages/property";
import Community from "../pages/community";
import My from "../pages/my";

const router = createBrowserRouter([
    {
        path: "/login", // 登录
        element: <Login />,
    },
    {
        path: "/register", // 注册
        element: <Register />,
    },
    {
        path: "/",
        element: <TabLayout />,
        children: [
            { index: true, loader: () => redirect("/home") },
            {
                path: "home", // 首页
                element: <Home />,
            },
            {
                path: "property", // 物业
                element: <Property />,
            },
            {
                path: "community", // 社区
                element: <Community />,
            },
            {
                path: "my", // 我的
                element: <My />,
                children: [
                    { index: true, element: <div>个人信息</div> },
                    { path: "address", element: <div>收货地址</div> },
                    { path: "address/new", element: <div>新增地址</div> },
                    { path: "settings", element: <div>设置</div> },
                ],
            },
        ]
    },
    {
        path: "*",
        element: <div style={{ padding: '20px', textAlign: 'center' }}>
            <h2>404 - 页面未找到</h2>
            <p>您访问的页面不存在</p>
        </div>
    }
]);

export default router;